<?php
//
$myfile = fopen($directory, "w") or die("Unable to open file for storage paths!");
fwrite($myfile, $packet[$i]);					
fclose($myfile);

// fwrite has a limit. So you may want to use it this way. PHP_EOL means a new line. So we are creating an array from the content of $txt using the explode command.
$myfile = fopen($directory, "w") or die("Unable to open file for storage paths!");
	$packet = explode(PHP_EOL, $txt);
	for ($i= 0; $i < count($packet); $i++) { 
		# code...
		fwrite($myfile, $packet[$i]);
	}				
fclose($myfile);

?>